import { lazy } from 'react'

// 自动导入所有页面组件
const pages = import.meta.glob('../pages/**/*.tsx')

// 构建路由配置
export const autoRoutes = Object.entries(pages).map(([path, importFn]) => {
  // 从文件路径提取路由路径
  // ../pages/home/index.tsx -> home
  // ../pages/ai/chat/index.tsx -> ai/chat
  const routePath = path
    .replace('../pages/', '')
    .replace('/index.tsx', '')
    .replace('.tsx', '')
  
  return {
    path: routePath,
    Component: lazy(importFn as any),
  }
})

// 调试：打印所有自动生成的路由
console.log('Auto generated routes:', autoRoutes.map(r => r.path))